<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <script src="../js/jquery.js"></script>
<%--    <style>--%>
<%--        *{--%>
<%--            font-weight: bold;--%>
<%--            --%>
<%--        }--%>
<%--    </style>--%>
</head>
<body>
    <table border="1" style="margin-left: 100px">
        <tr>
            <th>图书名称</th>
            <th>图书作者</th>
            <th>购买时间</th>
            <th>图书分类</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${list}" var="book">
            <tr>
                <td>${book.name}</td>
                <td>${book.author}</td>
                <td>${book.time}</td>
                <td>
                    <c:if test="${book.type==1}"> 计算机/软件</c:if>
                    <c:if test="${book.type==2}">小说/文摘</c:if>
                    <c:if test="${book.type==3}">杂项</c:if>
                </td>
                <td><a onclick="deletes(${book.id})">删除</a></td>
            </tr>
        </c:forEach>
    </table>
    <a  style="margin-left: 100px;font-weight: bold;text-decoration: none;" href="item/addUser.jsp">新增图书信息</a>
</body>
<script>
    $(function () {
        $('tr:first').css("backgroundColor","darkgray")
        $('tr:odd').css("backgroundColor","cornsilk")
    })
    function deletes(Id){
        if (confirm("确认删除这本书吗")===true) {
            $.ajax({
                url: "BooksDelete_Servlet",
                type: "get",
                data: "Id=" +Id,
                dataType: "text",
                success: function (data) {
                    if (data === "true") {
                        alert("删除成功!")
                        location.href = "BookManageSelect";
                    } else {
                        alert("删除失败！")
                    }
                }
            })
        }
    }
</script>
</html>
